#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minimumTotal(vector<vector<int>>& triangle) {
        int n = triangle.size(), ret = INT_MAX;
        vector<vector<int>> dp(n + 1, vector<int>(n + 1, INT_MAX));
        dp[0][0] = 0;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= i; j++) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1]) + triangle[i - 1][j - 1];
        for (int i = 1; i <= n; i++) ret = min(dp[n][i], ret);
        return ret;
    }
};